#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "bt_data.h"
#include "btree.h"
#include "Error.h"
#include "trend.h"
#include "word.h"

int main (int argc, char ** argv)
{
	BTree tree;
	TrendingList list;

	/* This line of code was necessary since declaring tree (but not
	 * setting it to null) corrupted the argument vector. */
	tree = NULL;

	if (argc != 3)
		Die ("Usage: %s startFile endFile\n", *argv);

	/* Retrieve words from both files */
	get_words (*(argv+1), &tree, FSTART);
	get_words (*(argv+2), &tree, FEND);

	/* Free the tree and calculate trending statistics */
	list = trend_init ();
	btree_free (&tree, list);

	/* Print statistics */
	trend_print_lists (list);

	/* Free trending list */
	trend_free (&list);
	
	return EXIT_SUCCESS;
}
